#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
class Solution {
    int _m, _n, _cnt;
    int dx[2] = { 1,0 };
    int dy[2] = { 0,1 };
    int count = 0;
    bool as[100][100];
public:
    int wardrobeFinishing(int m, int n, int cnt) {
        _m = m;
        _n = n;
        _cnt = cnt;
        dfs(0, 0, _cnt);
        return count;
    }
    void dfs(int i, int j, int cnt)
    {
        count++;
        as[i][j] = true;
        for (int k = 0; k < 2; k++)
        {
            int sum = 0;
            int x = i + dx[k];
            int y = j + dy[k];
            int d = x;
            int f = y;
            while (x)
            {
                sum += (x % 10);
                x /= 10;
            }
            while (y)
            {
                sum += (y % 10);
                y /= 10;
            }
            if (d >= 0 && d < _m && f >= 0 && f < _n && sum <= cnt && !as[d][f])
            {
                dfs(d, f, cnt);
            }
        }
    }
};